package com.fuhao.utils;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author zhang
 * @title: RabbitUtils
 * @projectName simplerabbit
 * @description: TODO
 * @date 2019/5/1820:25
 */
public class RabbitUtils {
    public static Connection getConnection() throws IOException, TimeoutException {
        //1.定义连接工厂
        ConnectionFactory factory = new ConnectionFactory();

        //2.设置服务地址
        factory.setHost("127.0.0.1");

        //3.设置端口号
        factory.setPort(5672);

        //4.设置账号信息、vhost
        factory.setUsername("rich");
        factory.setPassword("123456");
        factory.setVirtualHost("/rich");

        //5.获取连接
        Connection connection = factory.newConnection();

        return connection;
    }
}
